package com.xhwh.wx.controller;

import com.fasterxml.jackson.annotation.JsonView;
import com.xhwh.wx.orm.model.Artist;
import com.xhwh.wx.orm.service.ArtistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Collection;

/**
 * Created by zsq on 3/20/15.
 */
@Controller
@RequestMapping("/orm")
public class ArtistConsumer {
    @Autowired
    ArtistService artistService;

    public ArtistService getArtistService() {
        return artistService;
    }

    public void setArtistService(ArtistService artistService) {
        this.artistService = artistService;
    }

    @RequestMapping("/artistconsumer")
    //@JsonView(Artist.class)
    @ResponseBody
    public String showAllArtists(HttpServletResponse response)
    {
        response.setCharacterEncoding("UTF-8");
        Collection result = artistService.getAllArtists();
        return String.format("number of artists: %d",result.size());
    }

}
